package stone.parser;

import java.util.Iterator;
import java.util.List;

public class ASTList extends ASTree {
    protected List<ASTree> children;

    public ASTList(List<ASTree> children) {
        this.children = children;
    }

    @Override
    public ASTree child(int i) {
        return children.get(i);
    }

    @Override
    public int numChildren() {
        return children.size();
    }

    @Override
    public Iterator<ASTree> children() {
        return children.iterator();
    }

    @Override
    public String location() {
        for (ASTree t : children) {
            String s = t.location();
            if (s != null) {
                return s;
            }
        }
        return null;
    }

    @Override
    public boolean hasNext() {
        return children.iterator().hasNext();
    }

    @Override
    public ASTree next() {
        return children.iterator().next();
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder=new StringBuilder();
        stringBuilder.append("(");
        for (int i=0;i<children.size();i++){
            stringBuilder.append(children.get(i));
        }
        stringBuilder.append(")");
        return stringBuilder.toString();
    }
}
